package List存放map按照key值排序;

import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * @param null
 * @author oyz
 * @version 1.0
 * @description: TODO
 * @date 2022/2/18 16:18
 */
public class ListSort {


    public static void main(String[] args) {
        List<Map<String,String>> mapList = new ArrayList<>(3);
        Map<String,String> map3 = new TreeMap<>();
        map3.put("custNum","333");
        map3.put("custType","产品");
        Map<String,String> map1 = new TreeMap<>();
        map1.put("custNum","111");
        map1.put("custType","个人");
        Map<String,String> map2 = new TreeMap<>();
        map2.put("custNum","222");
        map2.put("custType","个人");
        mapList.add(map1);
        mapList.add(map2);
        mapList.add(map3);

        //mapList.stream().forEach(item->System.out.println(item));
        Map<String, String> collect = mapList.stream().collect(Collectors.toMap(item -> item.get("custNum"), item -> item.get("custType"),(k1,k2) -> k1));

        System.out.println(collect);
        System.out.println(collect.containsKey("222"));
        //mapList.forEach(item->System.out.println(item));

        //mapList.stream().collect(Collectors.toMap(User::getId, Function.identity(), (key1, key2) -> key2));
       /* for (Map<String, String> stringStringMap : mapList) {
            //System.out.println(stringStringMap);
            System.out.println(stringStringMap.get("custNum"));
        }*/
    }

}
